package com.cz.nongyetongv5.adapter;

import java.util.List;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.adapter.cache.ImageLoader;
import com.cz.nongyetongv5.adapter.config.CommonConstants;
import com.cz.nongyetongv5.bean.JianChaNeiRong;
import com.cz.nongyetongv5.bean.JingShiXinXi;

import android.content.Context;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class JingShiXinXiAdapter extends BaseAdapter {

	private Context context;

	private List data;

	private boolean mBusy = false;

	public void setFlagBusy(boolean busy) {
		this.mBusy = busy;
	}

	public JingShiXinXiAdapter(Context context, List data) {
		this.context = context;
		this.data = data;

	}

	@Override
	public int getCount() {
		return data == null ? 0 : data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.jianguanduixiang_jingshixinxi_item_layout, null);

			ViewHolder holder = new ViewHolder();

			holder.ivImage = (ImageView) convertView.findViewById(R.id.ivImage);

			ViewGroup llInfos = (ViewGroup) convertView
					.findViewById(R.id.llInfos);

			holder.tvInfo1 = (TextView) llInfos.getChildAt(0);

			holder.tvInfo2 = (TextView) llInfos.getChildAt(1);

			holder.tvInfo3 = (TextView) llInfos.getChildAt(2);

			holder.tvInfo4 = (TextView) llInfos.getChildAt(3);

			holder.tvInfo5 = (TextView) llInfos.getChildAt(4);

			convertView.setTag(holder);
		}

		ViewHolder holder = (ViewHolder) convertView.getTag();

		JingShiXinXi jingShiXinXi = (JingShiXinXi) getItem(position);

		String pre = "";

		switch (jingShiXinXi.getCategoryInt()) {
			case 1:
			case 3:
				pre = "产品";
				break;

			case 2:
			case 4:
				pre = "产地";
				break;
		}

		holder.tvInfo1
				.setText(pre + "认证类别:\u0020" + jingShiXinXi.getCategory());

		holder.tvInfo2.setText(Html.fromHtml("证书编号:\u0020"
				+ "<font color=\"#00B28C\">" + jingShiXinXi.getSerial()
				+ "</font>"));

		holder.tvInfo3.setText(pre + "名称:\u0020" + jingShiXinXi.getName());

		holder.tvInfo4.setText("有效期始:\u0020" + jingShiXinXi.getStartTime());

		switch (jingShiXinXi.getCategoryInt()) {
			case 1:
			case 2:
				// 三品一标已经过期ffff0000

				holder.tvInfo5.setText(Html.fromHtml("有效期终:&nbsp;"
						+ "<font color=\"red\">" + jingShiXinXi.getEndTime()
						+ "</font>"));
				break;
			case 3:
			case 4:
				// 三品一标将过期ffff0000
				holder.tvInfo5.setText(Html.fromHtml("有效期终:&nbsp;"
						+ "<font color=\"#F4C82D\">" + jingShiXinXi.getEndTime()
						+ "</font>"));

				break;

		}




		if (jingShiXinXi.getCategoryInt() == 2 || jingShiXinXi.getCategoryInt() == 4) {


			holder.ivImage.setVisibility(View.GONE);

		} else {


			switch (jingShiXinXi.getType()) {
				case 1:
					holder.ivImage.setImageResource(R.drawable.wugonghainongchanpin);
					holder.ivImage.setVisibility(View.VISIBLE);
					break;
				case 2:
					holder.ivImage.setImageResource(R.drawable.lvseshipin);
					holder.ivImage.setVisibility(View.VISIBLE);
					break;
				case 3:
					holder.ivImage.setImageResource(R.drawable.youjishipin);
					holder.ivImage.setVisibility(View.VISIBLE);
					break;

				case 4:
					holder.ivImage.setImageResource(R.drawable.dilibiaozhinongchanpin);
					holder.ivImage.setVisibility(View.VISIBLE);
					break;

				default:

					holder.ivImage.setVisibility(View.GONE);

					break;
			}
		}



		return convertView;
	}

	class ViewHolder {

		private ImageView ivImage;

		private TextView tvInfo1;

		private TextView tvInfo2;

		private TextView tvInfo3;

		private TextView tvInfo4;

		private TextView tvInfo5;

	}

}
